$all="/mnt/md1200/6/yjp/ASM/another_all.txt";
open(GENE,"$all");
%M1=();
$line=<GENE>;
$line=<GENE>;
$M1{'key'}="TRUE";
while ($line ne ""){
chomp($line);
@arr=split(/\t/,$line);

if(length($arr[12])==3){$M1{$arr[1]}=$arr[12];}

$line=<GENE>;
}
close(GENE);

$my_dir='/mnt/md1200/6/yjp/5hmc_analysis_hg19_new/ASM/varscan';

open (OUTRESULT,">>result.log.txt");
print OUTRESULT "filename\tT\tF\tN\n";
close(OUTRESULT);
$d='M2_M1.snp';
print "$d is operating\n";
open (OUTRESULT,">>result.log.txt");
$newdir = $my_dir."/$d";
@id_pre=split(/\./,$d);
@id=split(/_/,$id_pre[0]);

if (exists ${$id[0]}{key}){
$N=$T=$F=0;
open(SAMPLE,"$newdir");
open (OUTSAMPLE,">$d");
$sample=<SAMPLE>;
chomp($sample);
$header=$sample."\texits\n";
print OUTSAMPLE "$header";

$sample=<SAMPLE>;
while($sample ne ''){
	chomp($sample);
	@arrary=split(/\t/,$sample);
	$sample_id=join ":",$arrary[0],$arrary[1];
	$sample_genotype=$arrary[2].$arrary[3];
	if (exists ${$id[0]}{$sample_id}){
	if (${$id[0]}{$sample_id}=~/$sample_genotype/){$merge_outline=$sample."\tT\n";$T++;print OUTSAMPLE "$merge_outline";}
	else {$merge_outline=$sample."\tF\n";$F++;print OUTSAMPLE "$merge_outline";}
	}
	else {$merge_outline=$sample."\tN\n";$N++;print OUTSAMPLE "$merge_outline";}
	$sample=<SAMPLE>;
}
print OUTRESULT "$d:\t$T\t$F\t$N\n";
close(SAMPLE);
close(OUTSAMPLE);
close(OUTRESULT);
}
else {
$N=$T=$F=0;
open(SAMPLE,"$newdir");
open (OUTSAMPLE,">$d");
$sample=<SAMPLE>;
chomp($sample);
$header=$sample."\texits\n";
print OUTSAMPLE "$header";
$sample=<SAMPLE>;
while($sample ne ''){
chomp($sample);
	@arrary=split(/\t/,$sample);
	$sample_id=join ":",$arrary[0],$arrary[1];
	$sample_genotype=$arrary[2].$arrary[3];
	if (exists ${$id[1]}{$sample_id}){
	if (${$id[1]}{$sample_id}=~/$sample_genotype/){$merge_outline=$sample."\tT\n";$T++;print OUTSAMPLE "$merge_outline";}
	else {$merge_outline=$sample."\tF\n";$F++;print OUTSAMPLE "$merge_outline";}
	}
	else {$merge_outline=$sample."\tN\n";$N++;print OUTSAMPLE "$merge_outline";}
	$sample=<SAMPLE>;
}
print OUTRESULT "$d:\t$T\t$F\t$N\n";
close(SAMPLE);
close(OUTSAMPLE);
close(OUTRESULT);
}
